package com.lanou3g.code0418.control;

import java.util.concurrent.ForkJoinPool;

/**
 * Created by dllo on 18/4/18.
 */
public class Test03 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        addWithJoin(50000000L);

        long mid = System.currentTimeMillis();

        System.out.println("消耗时间:" + (mid - start) + "毫秒");

        addWithJoin(50000000L);

        long end = System.currentTimeMillis();

        System.out.println("-->" + (end - mid) + "毫秒");
    }

    public static void addWithNormal(long target) {

        long sum = 0;

        for (int i = 0; i <= target; i++) {
            sum += i;
        }
    }

    public static void addWithJoin(long target) {

        System.out.println("开始");

        SumTask task = new SumTask(0L, target);//专门用来启动Task的

        ForkJoinPool fjp = new ForkJoinPool(); //用来启动分配完的工作

        Long result = fjp.invoke(task); //启动任务 并计算结果

        System.out.println("结果是:" + " " + result);
    }
}
